# include "iostream"
# include "cmath"
# include "complex"

using namespace std;

// 设计一元二次方程的实现
// 例如 3x^2 + 2x + 5= 0;求解x的解
// 用户输入二次项系数a 一次项系数b和常数c 输入解
// 根据求根公式 

int main(){
    cout << "请输入一元二次方程的系数a b c:" << endl;
    double a, b, c;
    cin >> a >> b >> c;
    if(a == 0){
        cout << "这不是一元二次方程,a不可以等于0" << endl;
    }
    double deta = b*b - 4*a*c;
    if(deta > 0){
        cout << "方程有两个根：" << endl;
        double root1 = (-b + sqrt(deta))/(2*a);
        double root2 = (-b - sqrt(deta))/(2*a);
        cout << "root1 = " << root1 << "root2 = " << root2 << endl;
    }else if (deta == 0)
    {
        cout << "方程有一个根：" << endl;
        double root1 = (-b + deta)/(2*a);
        cout << "root = " << root1 << endl;;
    }else{
        cout << "方程有虚数根：" << endl;
        complex<double> root1 = (-b + sqrt(complex<double>(deta, 0))) / (2 * a);
        complex<double> root2 = (-b - sqrt(complex<double>(deta, 0))) / (2 * a);
        cout << "root1 = " << root1 << "root2 = " << root2 << endl;

    }
    return 0;
}